import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class ShenGaoZuiJinDeXiaoPengYou {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String one = sc.nextLine();
        String two = sc.nextLine();
        sc.close();
        String[] split = one.split(" ");
        String[] split1 = two.split(" ");

        int h = Integer.parseInt(split[0]);
        int n = Integer.parseInt(split[1]);

        PriorityQueue<Paire> pq = new PriorityQueue(n, new Comparator<Paire>() {
            @Override
            public int compare(Paire o1, Paire o2) {
                if (o1.getCha() == o2.getCha()) {
                    return o1.getH() - o2.getH();
                }
                return o1.getCha() - o2.getCha();
            }
        });

        for (int i = 0; i < split1.length; i++) {
            int tmp = Integer.parseInt(split1[i]);
            pq.add(new Paire(Math.abs(tmp - h), tmp));
        }

        while (!pq.isEmpty()) {
            System.out.print(pq.poll().getH() + " ");
        }

    }

    public static class Paire {
        private int cha;
        private int h;

        public Paire(int cha, int h) {
            this.cha = cha;
            this.h = h;
        }

        public int getCha() {
            return cha;
        }

        public int getH() {
            return h;
        }
    }
}
